<template>
    <div class="loading" :class="{active:loading}">
        <svg viewBox="25 25 50 50" :style="{width:svgSize,height:svgSize}">
            <circle cx="50" cy="50" r="20" fill="none"></circle>
        </svg>
        <span v-text="title" v-if="title"></span>
    </div>
</template>
<script>
export default {
    name: "Loading",
    props: {
        title: { type: String, default: '' },
        size: { type: [Number, String], default: '' },
        loading: { type: Boolean, default: true },
    },
    data () {
        return {};
    },
    computed: {
        svgSize () {
            if (!this.size) {
                return undefined
            } else if (this.size == 'small') {
                return '16px'
            } else if (this.size == 'later') {
                return '42px'
            } else if (this.size == 'medium') {
                return '30px'
            } else {
                return this.size
            }
        }
    },
    methods: {},
};
</script>
<style scoped lang="scss">
@keyframes loading-dash {
    0% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -40px;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -120px;
    }
}

.loading {
    position: absolute;
    z-index: 2;
    background-color: rgba(255, 255, 255, 0.9);
    margin: 0;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transition: opacity 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;

    svg {
        height: 42px;
        width: 42px;
        -webkit-animation: loading-rotate 2s linear infinite;
        animation: loading-rotate 2s linear infinite;
    }

    circle {
        -webkit-animation: loading-dash 1.5s ease-in-out infinite;
        animation: loading-dash 1.5s ease-in-out infinite;
        stroke-dasharray: 90, 150;
        stroke-dashoffset: 0;
        stroke-width: 2;
        stroke: #ea4c89;
        stroke-linecap: round;
    }

    span {
        margin-top: 18px;
        font-size: 14px;
        line-height: 16px;
    }

    &.active {
        opacity: 1;
        pointer-events: all;
    }
}
</style>
